package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.TLogistics;
import com.smz.entity.TVehicleCar;
import com.smz.entity.TVehicleDriver;
import com.smz.service.TVehicleDriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api
@RestController
public class TVehicleDriverController {

    @Autowired
    private TVehicleDriverService tVehicleDriverService;

    @ApiOperation("分页查询驾驶员")
    @GetMapping("/tVehicleDriver/{current}/{size}")
    public ResponseEntity<IPage<TVehicleDriver>> findTVehicleDriverPage(
            @PathVariable("current") int current,
            @PathVariable("size") int size){
        IPage<TVehicleDriver> page = tVehicleDriverService.findTVehicleDriverPage(current,size);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("ID分页查询驾驶员")
    @GetMapping("/tVehicleDriver/{current}/{size}/{driverId}")
    public ResponseEntity<IPage<TVehicleDriver>> findTVehicleDriverId(@PathVariable("current") int current,
                                                                      @PathVariable("size") int size,
                                                                      @PathVariable("driverId") int driverId){
        IPage<TVehicleDriver> page = tVehicleDriverService.findTVehicleDriverId(current,size,driverId);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("驾驶员名称,驾驶证号分页查询")
    @GetMapping("/tVehicleDriver/{current}/{size}/{driverName}/{driverLicense}")
    public ResponseEntity<IPage<TVehicleDriver>> findTVehicleDriverNN(@PathVariable("current") int current,
                                                                      @PathVariable("size") int size,
                                                                      @PathVariable("driverName") String driverName,
                                                                      @PathVariable("driverLicense") String driverLicense){
        if("null".equals(driverName)) driverName = null;
        if("null".equals(driverLicense)) driverLicense = null;
        IPage<TVehicleDriver> page = tVehicleDriverService.findTVehicleDriverNameNumber(current,size,driverName,driverLicense);
        return ResponseEntity.ok(page);
    }

    @ApiOperation("添加驾驶员")
    @PostMapping("/tVehicleDriver")
    public ResponseEntity<String> addTVehicleDriver(@RequestBody TVehicleDriver tVehicleDriver){
        tVehicleDriverService.saveOrUpdate(tVehicleDriver);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("修改驾驶员")
    @PutMapping("/tVehicleDriver")
    public ResponseEntity<String> modifyTVehicleDriver(@RequestBody TVehicleDriver tVehicleDriver){
        tVehicleDriverService.saveOrUpdate(tVehicleDriver);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("删除驾驶员")
    @DeleteMapping("/tVehicleDriver/{id}")
    public ResponseEntity<String> removeTVehicleDriver(@PathVariable("id") int id){
        tVehicleDriverService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("查询所有的车辆")
    @GetMapping("/TVehicleCarDriver")
    public ResponseEntity<List<TVehicleCar>> findCar(){
        List<TVehicleCar> tVehicleCar = tVehicleDriverService.findTVehicleCar();
        return ResponseEntity.ok(tVehicleCar);
    }

    @ApiOperation("查询所有的物流公司")
    @GetMapping("/TLogisticsDriver")
    public ResponseEntity<List<TLogistics>> findTLogistics(){
        List<TLogistics> tLogistics = tVehicleDriverService.findTLogistics();
        return ResponseEntity.ok(tLogistics);
    }

}
